<template>
    <div v-if="ac.infor.adminId">
      <h1>科室添加</h1>
      <table class="table table-bordered">
        <tbody>
            <tr>
                <td align="right">科室名称</td>
                <td>
                    <input type="text" v-model="query.departmentName"/>
                </td>
            </tr>
            <tr>
                <td align="right">科室人数</td>
                <td>
                    <input type="number" min="1" v-model="query.departmentNumber"/>
                </td>
            </tr>
            <tr>
                <td align="right">科室介绍</td>
                <td>
                    <textarea v-model="query.departmentDesc"></textarea>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="button" value="添加" class="btn btn-success" @click="ok"/>
                </td>
            </tr>
        </tbody>
      </table>
    </div>
    <div v-else>您还没有登录</div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref,reactive,onMounted } from 'vue';
import moment from 'moment';
import { useRoute,useRouter } from 'vue-router';
//接收值
const route=useRoute();
//跳转页面
const router=useRouter();

import {useCounterStore} from '@/stores/use'
const ac=useCounterStore();


let query:any=reactive
({
  "departmentName": "",
  "departmentNumber": "",
  "departmentDesc": "",
  "adminName": "admin"
})

const ok=()=>
{
    if(query.departmentName=="")
    {
        alert("科室名称不能为空");
        return;
    }
    if(query.departmentNumber=="")
    {
        alert("科室人数不能为空");
        return;
    }
    if(query.departmentDesc=="")
    {
        alert("科室介绍不能为空");
        return;
    }

    axios({
        url:'/api/Department/DepartmentAdd',
        method:'post',
        data:query
    })
    .then(res=>{
        console.log(res);
        if(res.data==-1)
        {
            alert("科室名称重复");
            return;
        }
        if(res.data>0)
        {
            alert("添加成功");
            router.push('/departmenList');
            return;
        }
        else
        {
            alert("添加失败");
            return;
        }
        
    })
    .catch(err=>{
        console.log(err);
        
    })


}




</script>

<style scoped>

</style>